

use "$rawdata\core_employee2019q1.dta", clear
gen byte faculty=(umetrics_occ=="Faculty"|umetrics_occ=="faculty")
ren institution_id submit_university

replace proportion=0 if proportion<0
replace proportion=1 if proportion>1 & proportion<.
bysort unique_award emp_number: egen temp=sum(faculty*proportion)
gsort unique_award -temp
by unique_award: gen temp2=_n

preserve
keep if temp2==1 & faculty==1
egen pinumber=group(emp_number)
keep unique_award pinumber
save "$data\pi_award", replace
restore

merge m:1 unique_award using "$data\pi_award", keep(1 3) nogen

drop if pi==.

gen year_end=substr(period_end,1,4)
destring year_end, replace
bysort emp_number year_end pinumber: egen temp3=sum(proportion)
gsort emp_number year_end -temp3
by emp_number year_end: gen temp4=_n

keep if temp4==1
ren year_end year
keep emp_number pinumber year
ren emp_number iris_employee_number

save "$data\pi", replace
